<?php
	$allSubItems = $this->getAllSubItems();
?>
<html>
<head>
<title>Confirmation Order</title>
<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('ves_vendors/css/warehouse.css')?>" media="all" />
<script type="text/javascript" src="<?php echo $this->getJsUrl('ves_vendors/warehouse/jquery-1.11.3.min.js')?>"></script>
<script type="text/javascript">
 $(function() {
		/* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
		/* For cell text alignment */
		$("table td:first-child, table th:first-child").addClass("first");
		/* For removing the last border */
		$("table td:last-child, table th:last-child").addClass("last");
});
</script>
</head>
<body>
<?php 
echo '<pre>';
	print_r($allSubItems);
	echo '</pre>';
?>
<div class="content">
<?php foreach($allSubItems as $key1 => $allItems): ?>
<form id="confirmation_order" method="post">
	<table class="order_items">
		<tr>
			<th style="width:10%;">Action</th>
			<th style="width:10%;">Image</th>
			<th style="width:10%;">Name</th>
			<th style="width:10%;">SKU</th>
			<th style="width:15%;">QTY</th>
			<th style="width:5%;">Weight</th>
			<th style="width:5%;">Total Weight</th>
			<th style="width:10%;">Shipping Type</th>
		<tr>
		
	<?php foreach($allItems as $key2 => $item): ?>
		<tr>
		<td><input type="checkbox" name="select_item"></td>
		<td><img width="60" src="<?php //echo $item['image']; ?>"/></td>
		<td><?php echo $item['name']; ?></td>
		<td><?php echo $item['sku']; ?></td>
		<td>
		<button type="button" onclick="minusQty('<?php echo $key1.$key2; ?>')"><img src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif')?>"></button>
		<input type="text" id="<?php echo 'qty-column'.$key1.$key2; ?>" 
			style="width:30px;text-align:center;" readonly="readonly" data="<?php echo $qty = $item['qty_ordered']; ?>" value="<?php echo $qty; ?>" />
		<button type="button" onclick="addQty('<?php echo $key1.$key2; ?>')"><img src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif')?>"></button>
		</td>
		<td><input id="<?php echo 'weight'.$key1.$key2;?>" type="text" readonly="readonly" style="border:0;width:30px;text-align:center;" value="<?php echo $weight = $item['weight']; ?>"/></td>
		<td><input id="<?php echo 'total_weight'.$key1.$key2;?>" type="text" readonly="readonly" style="border:0;width:30px;text-align:center;" value="<?php echo $qty * $weight ?>"/></td>
		<td><?php echo $item['shippingTypeLabel']; ?></td>
		</tr>
	<?php endforeach;?>
	</table>
	
	<div>
		<select name="warehouse_code">
			<option value="1">A</option>
			<option value="2">D</option>
			<option value="3">B</option>
			<option value="4">C</option>
		</select>	
		<input type="submit" value="submit"/>
	</div>
</form>
<?php endforeach;?>
</div>


<script type="text/javascript">
function minusQty(key){
	var weight = $('#weight'+key).val();
	var totalWeightObj = $('#total_weight'+key);
	var qtyObj = $('#qty-column'+key);
	var beforeQty = Number(qtyObj.val());
	if(beforeQty <= 1){
		var afterQty = 1;
	}else{
		var afterQty = beforeQty - 1;
	}
	qtyObj.val(afterQty);
	var totalWeight = accMul(afterQty,weight);
	totalWeightObj.val(totalWeight);
}
function addQty(key){
	var weight = $('#weight'+key).val();
	var totalWeightObj = $('#total_weight'+key);
	var qtyObj = $('#qty-column'+key);
	var beforeQty = Number(qtyObj.val());
	var maxQty = Number(qtyObj.attr('data'));
	if(beforeQty >= maxQty){
		var afterQty = maxQty;
	}else{
		var afterQty = parseInt(beforeQty) + 1;
	}
	qtyObj.val(afterQty);
	var totalWeight = accMul(afterQty,weight);
	totalWeightObj.val(totalWeight);
}

/*乘法函数*/
function accMul(arg1, arg2) {
     var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
     try {
         m += s1.split(".")[1].length;
     }
     catch (e) {
     }
     try {
         m += s2.split(".")[1].length;
     }
     catch (e) {
     }
     return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
 }
</script>
</body>
</html>